//  RefundStatusPay.m
//  XJMCustomer
//  Created by Mr.hu on 2017/10/26.
//  Copyright © 2017年 Mr.hu. All rights reserved.

#import "RefundStatusPay.h"

@interface RefundStatusPay ()
@property (weak, nonatomic) IBOutlet UILabel *Refund_statuslab;

@property (weak, nonatomic) IBOutlet UILabel *Residue_timelab; //剩余时间
@property (weak, nonatomic) IBOutlet UIButton *Cancel_applyBtn;  //同意退款
@property (weak, nonatomic) IBOutlet UIButton *Fix_ApplyBtn;    //拒绝退款
@property (weak, nonatomic) IBOutlet UILabel *Server_itemlab; //服务项目
@property (weak, nonatomic) IBOutlet UILabel *Server_timeprice;
@property (weak, nonatomic) IBOutlet UILabel *Server_exit; //退款原因
@property (weak, nonatomic) IBOutlet UILabel *Server_Exitprice;
@property (weak, nonatomic) IBOutlet UILabel *Server_Exittime;

@property (weak, nonatomic) IBOutlet UILabel *Refund_remindStatus;
@property (weak, nonatomic) IBOutlet UIView *Refund_OrderView;

@property (weak, nonatomic) IBOutlet UILabel *Refund_CircleFirst;
@property (weak, nonatomic) IBOutlet UILabel *Refund_CircleDetailFirst;

@property (weak, nonatomic) IBOutlet UILabel *Refund_CircleSecond;
@property (weak, nonatomic) IBOutlet UILabel *Refund_CircleDetailSecond;

@end

@implementation RefundStatusPay

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationController setNavigationBarHidden:NO];
    [self addLeftBtn:[UIImage imageNamed:@"fanhui"] Action:@selector(backToPrevious)];
    self.title = @"退款状态";
    
    self.Cancel_applyBtn.layer.cornerRadius = 15;
    self.Cancel_applyBtn.layer.borderColor = RGBA(234, 0, 0, 1).CGColor;
    self.Cancel_applyBtn.layer.borderWidth = 0.8;
    self.Fix_ApplyBtn.layer.cornerRadius = 15;
    self.Fix_ApplyBtn.layer.borderColor = RGBA(234, 0, 0, 1).CGColor;
    self.Fix_ApplyBtn.layer.borderWidth = 0.8;
    
    self.Refund_CircleFirst.layer.cornerRadius = 4;
    self.Refund_CircleFirst.layer.masksToBounds = YES;
    self.Refund_CircleSecond.layer.cornerRadius = 4;
    self.Refund_CircleSecond.layer.masksToBounds = YES;
    
    [self refundserverStatusPay];
    
}

- (void)refundserverStatusPay{
    
    [XJHttpClass ExitPayDetailToken:[XJToolClass getToken] refund_id:self.SubmitExit_OrderID andFinishblock:^(id response, NSString *errStr) {
        
        if (errStr) {
            [XJToolClass tipAnimationWith:errStr];
        }else{
            NSDictionary * dictdata = response[@"data"];
            NSString * order_status = dictdata[@"status"]; //0已同意退款，1等待商家确认 。2已拒绝退款 3已完成退款
            if ([order_status isEqualToString:@"0"]) {
                
                self.Refund_statuslab.text = @"请及时处理退款订单";
                if (dictdata[@"refund_reason"]) {
                    self.Refund_remindStatus.text = [NSString stringWithFormat:@"客户因%@申请退款",dictdata[@"refund_reason"]];
                }else{
                    self.Refund_remindStatus.text = [NSString stringWithFormat:@"客户申请退款"];
                }
                
                self.Residue_timelab.text = [NSString stringWithFormat:@"还剩%@",dictdata[@"exprise"]];
                self.Residue_timelab.hidden = NO;
                
                self.Refund_CircleDetailFirst.text = @"技师同意或者超时未处理,系统将退款给客户。";
                self.Refund_CircleDetailSecond.text = @"如果技师连续拒绝三次,客户可以联系客服进行处理。";
                self.Refund_CircleSecond.hidden = NO;
                self.Refund_CircleDetailSecond.hidden = NO;
                
            }else if ([order_status isEqualToString:@"1"]){
                
                self.Refund_statuslab.text = @"请及时处理退款订单";
                if (dictdata[@"refund_reason"]) {
                    self.Refund_remindStatus.text = [NSString stringWithFormat:@"客户因%@申请退款",dictdata[@"refund_reason"]];
                }else{
                    self.Refund_remindStatus.text = [NSString stringWithFormat:@"客户申请退款"];
                }
                
                self.Residue_timelab.text = [NSString stringWithFormat:@"还剩%@",dictdata[@"exprise"]];
                self.Residue_timelab.hidden = NO;
                self.Refund_CircleDetailFirst.text = @"技师同意或者超时未处理,系统将退款给客户。";
                self.Refund_CircleDetailSecond.text = @"如果技师连续拒绝三次,客户可以联系客服进行处理。";
                self.Refund_CircleSecond.hidden = NO;
                self.Refund_CircleDetailSecond.hidden = NO;
                
            }else if ([order_status isEqualToString:@"2"]){
                
                self.Refund_statuslab.text = @"请及时处理退款订单";
                if (dictdata[@"refund_reason"]) {
                    if ([dictdata[@"refund_reason"] isEqualToString:@"选填"]) {
                        self.Refund_remindStatus.text = [NSString stringWithFormat:@"客户申请退款"];
                    }else{
                    self.Refund_remindStatus.text = [NSString stringWithFormat:@"客户因%@申请退款",dictdata[@"refund_reason"]];
                    }
                }else{
                    self.Refund_remindStatus.text = [NSString stringWithFormat:@"客户申请退款"];
                }
                
                self.Residue_timelab.text = [NSString stringWithFormat:@"还剩%@",dictdata[@"exprise"]];
                self.Residue_timelab.hidden = NO;
                self.Refund_CircleDetailFirst.text = @"技师同意或者超时未处理,系统将退款给客户。";
                self.Refund_CircleDetailSecond.text = @"如果技师连续拒绝三次,客户可以联系客服进行处理。";
                self.Refund_CircleSecond.hidden = NO;
                self.Refund_CircleDetailSecond.hidden = NO;
                
            }else if ([order_status isEqualToString:@"3"]){
                
                self.Refund_statuslab.text = @"客户申请成功,成功退款给客户!";
                if (dictdata[@"refund_reason"]) {
                    self.Refund_remindStatus.text = [NSString stringWithFormat:@"客户因%@申请退款",dictdata[@"refund_reason"]];
                }else{
                    self.Refund_remindStatus.text = [NSString stringWithFormat:@"客户申请退款"];
                }
                
                self.Refund_CircleDetailFirst.text = @"如有疑问,您可以在【客服中心】直接拨打电话,或者在【设置】-【反馈中心】里面填写反馈信息,我们都会及时处理!";
                self.Refund_CircleSecond.hidden = YES;
                self.Refund_CircleDetailSecond.hidden = YES;
                
                self.Residue_timelab.text = [NSString stringWithFormat:@"还剩%@",dictdata[@"exprise"]];
                self.Residue_timelab.hidden = NO;
            }
            
            self.Server_itemlab.text = dictdata[@"goods_name"];
            self.Server_timeprice.text = [NSString stringWithFormat:@"%@元/%@分",dictdata[@"goods_price"],dictdata[@"server_time"]];
            self.Server_exit.text = [NSString stringWithFormat:@"退款原因 : %@",dictdata[@"refund_reason"]];
            self.Server_Exitprice.text = [NSString stringWithFormat:@"退款金额 : %@",dictdata[@"refund_money"]];
            self.Server_Exittime.text = [NSString stringWithFormat:@"申请时间 : %@",dictdata[@"refundTime"]];
            
            }
    }];
}

//同意退款
- (IBAction)Cancel_ApplyMeth:(id)sender {
    //0同意，1不同意
    UIAlertController * aler = [UIAlertController alertControllerWithTitle:@"同意退款" message:nil preferredStyle:0];
    UIAlertAction * actionone = [UIAlertAction actionWithTitle:@"确定" style:0 handler:^(UIAlertAction *action) {
        [XJHttpClass teachAgreeOrNotToken:[XJToolClass getToken] refund_id:self.SubmitExit_OrderID  is_success:@"0" andFinishblock:^(id response, NSString *errStr) {
            if (errStr) {
                [XJToolClass tipAnimationWith:errStr];
            }else{
                [XJToolClass tipAnimationWith:@"已提交请等待！"];
            }
        }];
    }];
    
    UIAlertAction * actiontwo = [UIAlertAction actionWithTitle:@"取消" style:0 handler:^(UIAlertAction *action) {
       
    }];
    
    [aler addAction:actionone];
    [aler addAction:actiontwo];
    [self presentViewController:aler animated:YES completion:nil];
}

//拒绝退款
- (IBAction)Fix_ApplyMeth:(id)sender {
    
    //0同意，1不同意
    UIAlertController * aler = [UIAlertController alertControllerWithTitle:@"拒绝退款" message:nil preferredStyle:0];
    UIAlertAction * actionone = [UIAlertAction actionWithTitle:@"确定" style:0 handler:^(UIAlertAction *action) {
        [XJHttpClass teachAgreeOrNotToken:[XJToolClass getToken] refund_id:self.SubmitExit_OrderID  is_success:@"1" andFinishblock:^(id response, NSString *errStr) {
            if (errStr) {
                [XJToolClass tipAnimationWith:errStr];
            }else{
                [XJToolClass tipAnimationWith:@"已提交请等待！"];
            }
        }];
    }];
    
    UIAlertAction * actiontwo = [UIAlertAction actionWithTitle:@"取消" style:0 handler:^(UIAlertAction *action) {
        
    }];
    
    [aler addAction:actionone];
    [aler addAction:actiontwo];
    [self presentViewController:aler animated:YES completion:nil];
    
}

@end
